import path from 'path'

export default {
  // Global page headers: https://go.nuxtjs.dev/config-head
  target: 'static', // build打包用server，generate用static 默认 server
  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    title: 'vue-nuxt-demo',
    htmlAttrs: {
      lang: 'en'
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
      { name: 'format-detection', content: 'telephone=no' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },

  // env环境变量
  // env: {
  //   // 你在页面的script中打印process.env得到的是一个空数组{}，但是你用process.env.BASE_URL在上面的配置都完整的情况下是可以直接在页面中使用的
  //   dev: {
  //     MODE: 'development',
  //     BASE_URL: 'http://localhost:8080/jeecg-boot',
  //   },
  //   pro: {
  //     MODE: 'production',
  //     BASE_URL: 'https://fakestoreapi.com',
  //   },
  //   test: {
  //     MODE: 'test',
  //     BASE_URL: 'https://fakestoreapi.com',
  //   },
  // },
  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
    "element-ui/lib/theme-chalk/index.css",
    '@/assets/styles/reset.css',
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
    // srr:true/服务端渲染 false/只在客户端渲染
    { src:"@/plugins/ElementUI",ssr: true},
    { src:'@/plugins/axios.js', srr: true },
    { src:'@/plugins/persistedState.js', ssr: false },
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,
  loading: false,

  router: {
    middleware: 'auth'
  },


  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
  ],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    // https://go.nuxtjs.dev/axios
    '@nuxtjs/axios',
    // proxy
    '@nuxtjs/proxy',
    '@nuxtjs/style-resources',
    // cookie持久化 this.$cookies
    'cookie-universal-nuxt'
  ],
  styleResources: {
    less: [
      '@/assets/styles/common-style.less',
    ]
  },
  // Axios module configuration: https://go.nuxtjs.dev/config-axios
  axios: {
    // Workaround to avoid enforcing hard-coded localhost:3000: https://github.com/nuxt-community/axios-module/issues/308
    proxy: true,
    // timeout: 10000,
    baseURL: 'http://localhost:8080/jeecg-boot', // 可以配置 baseURL
    withCredentials: true,  // 确保发送带有身份验证信息（如 Cookies）
    // baseURL: process.env._ENV =='production'?'':'http://localhost:8080/jeecg-boot', // 设置默认的 API 基础 URL
  },
  vue: {
    config: {
      devtools: true // 启用 Vue Devtools
    }
  },
  // 配置跨域
  proxy: {
    '/api': {
      // 本地服务接口地址
      target: 'http://localhost:8080/jeecg-boot',
      // ws: true,
      pathRewrite: {
        '^/api': '',
      },
      changeOrigin: true,  // 改变请求头中的 origin 字段
      secure: false,  // 如果是 HTTPS 还需要加上 secure: false
      withCredentials: true  // 如果需要带上 Cookies
    },
  },
  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    // 避免重复打包
    vendor: ['element-ui'], // 添加模块，配置只打包一次，减少应用bundle的体积
    // 将内嵌CSS样式提取到外部
    extractCSS: { allChunks: true },
    // babel: {
    //   plugins: [
    //     ["component", { "libraryName": "element-ui", "styleLibraryName": "theme-chalk" }]
    //   ]
    // },
    extend(config, { isDev, isClient }) {
      // 添加别名
      config.resolve.alias['@assets'] = path.resolve(__dirname, 'assets')
      config.resolve.alias['@components'] = path.resolve(__dirname, 'components')
      config.resolve.alias['@plugins'] = path.resolve(__dirname, 'plugins')
      // 去掉console打印
      if (isClient && !isDev) {
        config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
      }
    },
  },
  server: {
    host: '0.0.0.0',
    // port: '3000',
  },
}
